package com.incar.chuxing.base;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;

import com.incar.chuxing.utils.zxing.android.BeepManager;
import com.incar.chuxing.utils.zxing.android.CaptureActivityHandler;
import com.incar.chuxing.utils.zxing.android.InactivityTimer;
import com.incar.chuxing.utils.zxing.camera.CameraManager;
import com.incar.chuxing.utils.zxing.view.ViewfinderView;
import com.google.zxing.Result;

/**
 * Created by Michael Pi on 2016/12/10.
 */

public class BaseScanActivity extends Activity {
    public CameraManager cameraManager;
    public ViewfinderView viewfinderView;
    public InactivityTimer inactivityTimer;
    public BeepManager beepManager;
    public CaptureActivityHandler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public ViewfinderView getViewfinderView() {
        return viewfinderView;
    }

    public CameraManager getCameraManager() {
        return cameraManager;
    }

    public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
        inactivityTimer.onActivity();

        boolean fromLiveScan = barcode != null;
        //这里处理解码完成后的结果，此处将参数回传到Activity处理
        if (fromLiveScan) {
            beepManager.playBeepSoundAndVibrate();

         /*   ToastCompat.makeText(this, "扫描成功", Toast.LENGTH_SHORT).show();*/

            Intent intent = getIntent();
            intent.putExtra("codedContent", rawResult.getText());
            intent.putExtra("codedBitmap", barcode);
            setResult(RESULT_OK, intent);
            finish();
        }
    }

    public void drawViewfinder() {
        viewfinderView.drawViewfinder();
    }

    public Handler getHandler() {
        return handler;
    }
}
